from typing import Tuple
import pygame

from game.ui.ui import UI
from game.sound import GameMusicManager
from game.ui.widgets.image import ImageWidget
from game.data.assets.assetManager import load_image
from game.sprites.sprites import SpritesContainer, GroupsContainer, background
from game.container import CONSTANT


max_health = 100


class GameMenu(UI):
    def __init__(self,
                 groups: Tuple[pygame.sprite.LayeredUpdates, ...],
                 ):
        super().__init__(groups)


        # ====================
        # = Background Image =
        # ====================
        self.background = ImageWidget(
            self.display_surface,
            background,
            background.get_rect().center,
            self.groups
        )
        self.background.kill()

        # ===================
        # = STAT UI =
        # ===================

        self.health_bar_rect = pygame.Rect((20, 20), (500, 50))
        # self.hotbar = ImageWidget(
        #     self.display_surface,
        #     load_image("test/hotbar.png"),
        #     (200, 700),
        #     self.groups)

    def show_bar(self, current_amount: float, max_amount, bar_color, bg_rect: pygame.Rect):
        # # calculate the rects
        # ratio = current_amount / max_amount
        # current_bar_width = bg_rect.width * ratio
        # current_bar_rect = bg_rect.copy().inflate(-6, -6)
        # current_bar_rect.width = current_bar_width

        # # draw the two bars
        # pygame.draw.rect(self.display_surface, 'black', bg_rect, 3)  # 描边
        # pygame.draw.rect(self.display_surface, bar_color, current_bar_rect)

        pass

    def show_switch(self):
        pygame.draw.rect(self.display_surface, CONSTANT.APP.Yellow, self.hotbar.rect, 3)

    def switch_to(self, key: int):
        from game.sprites.player.inventory import HOTBAR_SLOTS
        SpritesContainer.PLAYER.player.inventory.holdingSlot = HOTBAR_SLOTS[key - 1]

    def show_hotbar(self, hotbar_rect):
        pass
        # self.display_surface.blit(SpritesContainer.PLAYER.player.inventory.holdingItem.id.image, hotbar_rect)

    def update(self) -> None:
        if not GameMusicManager.is_channel_busy():
            GameMusicManager.play()
        super().update()

        # self.show_bar(SpritesContainer.PLAYER.player.stat.health, max_health, 'red', self.health_bar_rect)
        # self.show_hotbar(self.hotbar.rect)

